﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernateTest.AutoMapping.Conventions
{
    using System.Diagnostics;
    using FluentNHibernate.Conventions;
    using FluentNHibernate.Conventions.Inspections;
    using FluentNHibernate.Conventions.Instances;
    using FluentNHibernate.Mapping;

     class HasOneToOneConvention : IHasOneConvention
    {
        public void Apply(IOneToOneInstance instance)
        {
            Type inferredType = ((IOneToOneInspector)instance).Class.GetUnderlyingSystemType();
            Type persistentType = _mapProxyInterfaceTypeToPersistentType(inferredType);
            instance.LazyLoad(Laziness.NoProxy);
            //Self association
            if (referenceType == entityType)
                colName = "PARENT_ID";
            else
                colName = propertyName.ToDatabaseName() + "_ID";

            instance.Column(colName);
            instance.Cascade.None();
            Debug.WriteLine("----ReferenceConvention----" + instance.EntityType + " referenceType:" + referenceType);


            instance.LazyLoad(Laziness.NoProxy);
            Debug.WriteLine("----OneToOneInstance ----");
        }
    }
}
